resolve ambiguous calling of real_babl_log with va_args
authorPaul Fredrickson <p_fredrickson@hotmail.com>
Tue, 18 Mar 2014 03:17:43 +0000 (20:17 -0700)
committerDaniel Sabo <DanielSabo@gmail.com>
Thu, 20 Mar 2014 10:08:29 +0000 (03:08 -0700)
In babl-internal.h there are two different ways of calling real_babl_log.
One matches the macro definitions of babl_log which expects an arbitrary
number of parameters, and the other is to pass a va_list used to access
those parameters. The latter case can be found in the function definition
of babl_log when an appropriate macro definition is not selected.

It may be that some platforms implement varargs in such a way that
passing a va_list pointing to the params of another call stack is the
same as passing those parameters directly, but that definitely isn't
the case on mac OS X, where this results in corrupted strings when
calling babl_log or babl_fatal.

The solution here is to create a varargs-enabled version of real_babl_log
that accepts a va_list, and have all calls eventually call into that.

(This may not be seen under normal configurations. This was discovered
while trying to build with a hand-crafted config.h in Xcode.)

babl/babl-internal.h

index 38b59b141549dd65f6cfcdb5c18a1ef8315ff577..cc05660f9100c693f3ee7b5fc4a87d614d6d8d5e 100644 (file)
@@ -112,14 +112,13 @@ int      babl_type_is_symmetric         (const Babl     *babl);
 int babl_backtrack (void);
 
 static inline void
-real_babl_log (const char *file,
-               int         line,
-               const char *function,
-               const char *fmt, ...)
+real_babl_log_va(const char *file,
+                 int         line,
+                 const char *function,
+                 const char *fmt,
+                 va_list     varg)
 {
   Babl *extender = babl_extender();
-  va_list  varg;
-
 
   if (extender != babl_extension_quiet_log())
     {
@@ -129,15 +128,26 @@ real_babl_log (const char *file,
       fprintf (stdout, "%s:%i %s()\n\t", file, line, function);
     }
 
-  va_start (varg, fmt);
   vfprintf (stdout, fmt, varg);
-  va_end (varg);
 
   fprintf (stdout, "\n");
   fflush (NULL);
   return;
 }
 
+static inline void
+real_babl_log (const char *file,
+               int         line,
+               const char *function,
+               const char *fmt, ...)
+{
+  va_list  varg;
+
+  va_start (varg, fmt);
+  real_babl_log_va(file, line, function, fmt, varg);
+  va_end (varg);
+}
+
 /* Provide a string identifying the current function, non-concatenatable */
 #ifndef G_STRFUNC
 #if defined (__GNUC__)
@@ -180,7 +190,7 @@ babl_log (const char *format, ...)
 {
   va_list args;
   va_start (args, format);
-  real_babl_log (__FILE__, __LINE__, G_STRFUNC, format, args);
+  real_babl_log_va (__FILE__, __LINE__, G_STRFUNC, format, args);
   va_end (args);
 }
 static inline void
@@ -188,7 +198,7 @@ babl_fatal (const char *format, ...)
 {
   va_list args;
   va_start (args, format);
-  real_babl_log (__FILE__, __LINE__, G_STRFUNC, format, args);
+  real_babl_log_va (__FILE__, __LINE__, G_STRFUNC, format, args);
   va_end (args);
   babl_die();
 }